package com.neutech.Util;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 *图片工具类，1、读取图片2、防止多次读取
 */
public class ImageUtils {
    /**
     * 存储图片的地方 Hashmap查找快
     */
    private static final Map<String,Image> imgMap = new HashMap<>();
    static {
        /**
         * for循环读取8张黄色坦克图片
         * 出现不显示坦克是因为，读图片和绘制不是一个线程，还没读好就绘制了
         * 解决办法，给窗口添加刷新
         */
//        imgMap.put("ytank1",getImage("com/neutech/img/ytank/ytank1.png"));

//        for (int i = 1; i < 9; i++) {
//
//            imgMap.put("ytank" + i ,getImage("com/neutech/img/ytank/ytank" + i +".png"));
//        }
        /**
         * 读取黄素坦克
         */
        for (int i = 1; i < 5; i++) {
            for (int j = 1; j < 9; j++) {
                imgMap.put("tank_y_" + i + "_" +j,
                        getImage("com/neutech/img/tank/tank_y_" + i +"_" +j +".png"));
            }
        }

        /**
         * 读取白色坦克
         */
        for (int i = 1; i < 5; i++) {
            for (int j = 1; j < 9; j++) {
                imgMap.put("tank_w_" + i + "_" +j,
                        getImage("com/neutech/img/tank/tank_w_" + i +"_" +j +".png"));
            }
        }


        /**
         * 图片读不出来地址可以右键在左面的图片进行复制
         */
//        imgMap.put("bullet" ,getImage("com/neutech/img/bullet/b.png"));
        imgMap.put("bullet_up" ,getImage("com/neutech/img/bullet/bulletup.png"));
        imgMap.put("bullet_right" ,getImage("com/neutech/img/bullet/bulletright.png"));
        imgMap.put("bullet_down" ,getImage("com/neutech/img/bullet/bulletdown.png"));
        imgMap.put("bullet_left" ,getImage("com/neutech/img/bullet/bulletleft.png"));
        /**
         * 读取两张强的图片
         */
        imgMap.put("brick_wall",getImage("com/neutech/img/terrain/brick_wall.png"));
        imgMap.put("iron_wall",getImage("com/neutech/img/terrain/iron_wall.png"));
        /**
         * 读取水冰草的图片
         */
        imgMap.put("water1",getImage("com/neutech/img/terrain/water1.png"));
        imgMap.put("water2",getImage("com/neutech/img/terrain/water2.png"));

        //冰
        imgMap.put("ice",getImage("com/neutech/img/terrain/ice.png"));

        //草
        imgMap.put("grass",getImage("com/neutech/img/terrain/grass.png"));
        //读取界面图片
        imgMap.put("tank_main",getImage("com/neutech/img/tank_main.png"));


        //家在老家的两张图片
        imgMap.put("home_live",getImage("com/neutech/img/home_live.png"));
         imgMap.put("home_die",getImage("com/neutech/img/home_die.png"));

          //读一下空白图
        imgMap.put("space",getImage("com/neutech/img/space.png"));
        //读取结算图
        imgMap.put("tank_last",getImage("com/neutech/img/tank_last.png"));
        //读取爆炸图
        imgMap.put("tank_sprite_309",getImage("com/neutech/img/terrain/tank_sprite_309.png"));
        imgMap.put("tank_sprite_310",getImage("com/neutech/img/terrain/tank_sprite_310.png"));
        imgMap.put("tank_sprite_311",getImage("com/neutech/img/terrain/tank_sprite_311.png"));

        //读取结算页面的数字图片
        imgMap.put("number_01",getImage("com/neutech/img/summaryNumber/number_01.png"));
        imgMap.put("number_02",getImage("com/neutech/img/summaryNumber/number_02.png"));
        imgMap.put("number_03",getImage("com/neutech/img/summaryNumber/number_03.png"));
        imgMap.put("number_04",getImage("com/neutech/img/summaryNumber/number_04.png"));
        imgMap.put("number_05",getImage("com/neutech/img/summaryNumber/number_05.png"));
        imgMap.put("number_06",getImage("com/neutech/img/summaryNumber/number_06.png"));
        imgMap.put("number_07",getImage("com/neutech/img/summaryNumber/number_07.png"));
        imgMap.put("number_08",getImage("com/neutech/img/summaryNumber/number_08.png"));
        imgMap.put("number_09",getImage("com/neutech/img/summaryNumber/number_09.png"));
        imgMap.put("number_10",getImage("com/neutech/img/summaryNumber/number_10.png"));
        imgMap.put("number_11",getImage("com/neutech/img/summaryNumber/number_11.png"));
        imgMap.put("number_12",getImage("com/neutech/img/summaryNumber/number_12.png"));
        imgMap.put("number_13",getImage("com/neutech/img/summaryNumber/number_13.png"));
        imgMap.put("number_14",getImage("com/neutech/img/summaryNumber/number_14.png"));
        imgMap.put("number_15",getImage("com/neutech/img/summaryNumber/number_15.png"));
        imgMap.put("number_16",getImage("com/neutech/img/summaryNumber/number_16.png"));
        imgMap.put("number_17",getImage("com/neutech/img/summaryNumber/number_17.png"));
        imgMap.put("number_18",getImage("com/neutech/img/summaryNumber/number_18.png"));
        imgMap.put("number_19",getImage("com/neutech/img/summaryNumber/number_19.png"));
        imgMap.put("number_20",getImage("com/neutech/img/summaryNumber/number_20.png"));
        imgMap.put("number_21",getImage("com/neutech/img/summaryNumber/number_21.png"));
        imgMap.put("number_22",getImage("com/neutech/img/summaryNumber/number_22.png"));
        imgMap.put("number_23",getImage("com/neutech/img/summaryNumber/number_23.png"));
        imgMap.put("number_24",getImage("com/neutech/img/summaryNumber/number_24.png"));
        imgMap.put("number_25",getImage("com/neutech/img/summaryNumber/number_25.png"));
        imgMap.put("number_26",getImage("com/neutech/img/summaryNumber/number_26.png"));
        imgMap.put("number_27",getImage("com/neutech/img/summaryNumber/number_27.png"));
        imgMap.put("number_28",getImage("com/neutech/img/summaryNumber/number_28.png"));
        imgMap.put("number_29",getImage("com/neutech/img/summaryNumber/number_29.png"));
        imgMap.put("number_30",getImage("com/neutech/img/summaryNumber/number_30.png"));
        imgMap.put("number_31",getImage("com/neutech/img/summaryNumber/number_31.png"));
        imgMap.put("number_32",getImage("com/neutech/img/summaryNumber/number_32.png"));
        imgMap.put("number_33",getImage("com/neutech/img/summaryNumber/number_33.png"));
        imgMap.put("number_34",getImage("com/neutech/img/summaryNumber/number_34.png"));
        //获取道具的图片
        imgMap.put("prop_01",getImage("com/neutech/img/prop/prop_01.png"));
        imgMap.put("prop_02",getImage("com/neutech/img/prop/prop_02.png"));
        imgMap.put("prop_03",getImage("com/neutech/img/prop/prop_03.png"));
        imgMap.put("prop_04",getImage("com/neutech/img/prop/prop_04.png"));
        imgMap.put("prop_05",getImage("com/neutech/img/prop/prop_05.png"));
        imgMap.put("prop_06",getImage("com/neutech/img/prop/prop_06.png"));
        imgMap.put("prop_07",getImage("com/neutech/img/prop/prop_07.png"));
        imgMap.put("prop_08",getImage("com/neutech/img/prop/prop_08.png"));
        imgMap.put("prop_09",getImage("com/neutech/img/prop/prop_09.png"));
        imgMap.put("prop_10",getImage("com/neutech/img/prop/prop_10.png"));
        imgMap.put("prop_11",getImage("com/neutech/img/prop/prop_11.png"));


    }
    public static Image getValue(String Key){
        return imgMap.get(Key);
    }
    /***
     * 读取图片的地方
     * @param path
     * @return
     */
    public static Image getImage(String path) {
        Image image = null;
        try {
            /**
             * 下面的要用image接受一下
             */
           image= ImageIO.read(ImageUtils.class.getClassLoader().getResourceAsStream(path));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return image;
    }

}
